#include<bits/stdc++.h>
#define N 10000000
#define mod 1000000007
#define pii pair<ll,ll>
#define ll long long int
#define lli unsigned long long int
#ifndef ONLINE_JUDGE
#define debug(x) cerr<<#x<<" "; _print(x);cerr<<endl;
#else
#define debug(x)
#endif
#define pv(v){for(auto i:v)cout<<i<<" ";cout<<endl;}
#define fbo find_by_order
#define ook order_of_key
#define read(v){for(auto &i:v)cin>>i;}
using namespace std;
void _print(int x){cerr<<x;}
void _print(bool x){cerr<<x;}
void _print(char x){cerr<<x;}
void _print(ll x){cerr<<x;}
void _print(double x){cerr<<x;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
bool sieve[N+1];
void createSieve()
{
for(int i=2;i<=N;i++)sieve[i] = true;
for(int i=2;i*i<=N;i++)
{
if(sieve[i])
{
for(int j=i*i;j<=N;j+=i)
{
sieve[j] = false;
}
}
}
}
vector<ll>primes;
void createPrimes()
{
for(int i=2;i<=N;i++)
{
if(sieve[i])primes.push_back(i);
}
return;
}
int power(long long x, unsigned int y, int p)
{
int res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0) return 0; // In case x is divisible by p;
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
bool isPalindromee(string str)
{
int start = 0;
int end = str.length()-1;
while(start<end)
{
if(str[start++]!=str[end--])return false;
}
return true;
}
vector<int> prefix_kmp(string str)
{
int n = str.size();
vector<int>pi(n,0);
for(int i=1;i<n;i++)
{
int j = pi[i-1];
while(j>0 && str[i]!=str[j])
{
j = pi[j-1];
}
if(str[i]==str[j])j++;
pi[i] = j;
}
return pi;
}
vector<int> rabin_karp_patternMatch(string s,string t)
{
vector<int>occurences;
const int p = 31;
int S = s.size(), T = t.size();
vector<long long> p_pow(max(S, T));
p_pow[0] = 1;
for (int i = 1; i < (int)p_pow.size(); i++)
p_pow[i] = (p_pow[i-1] * p) % mod;
vector<long long> h(T + 1, 0);
for (int i = 0; i < T; i++)
h[i+1] = (h[i] + (t[i] - 'a' + 1) * p_pow[i]) % mod;
long long h_s = 0;
for (int i = 0; i < S; i++)
h_s = (h_s + (s[i] - 'a' + 1) * p_pow[i]) % mod;
for (int i = 0; i + S - 1 < T; i++) {
long long cur_h = (h[i+S] + mod - h[i]) % mod;
if (cur_h == h_s * p_pow[i] % mod)
occurences.push_back(i);
}
return occurences;
}
vector<int> z_function(string str)
{
int n = str.size();
vector<int>z(n,0);
for(int i=1,l=0,r=0;i<n;i++)
{
if(i<=r)z[i] = min(z[i-l],r-i+1);
while(i+z[i]<n && str[z[i]]==str[i+z[i]])++z[i];
if(i+z[i]-1>r)
{
l = i;
r = i+z[i]-1;
}
}
return z;
}
ll compute_hash(string str)
{
ll hashValue = 0;
ll p = 31;
int n = str.size();
ll pow = 1;
for(ll i=0;i<n;i++)
{
hashValue+=((str[i]-'a'+1)*pow)%mod;
pow = (pow*p)%mod;
}
return hashValue;
}
class SegmentTree{
public:
vector<int>seg;
public: SegmentTree(int n)
{
seg.resize(4*n+1);
}
void BuildSegmentTree(int index,int low,int high,vector<int>&v)
{
if(low==high)
{
seg[index] = v[low];
return;
}
int mid = (low+high)/2;
BuildSegmentTree(2*index+1,low,mid,v);
BuildSegmentTree(2*index+2,mid+1,high,v);
seg[index] = min(seg[2*index+1],seg[2*index+2]);
}
int query(int index,int low,int high,int l,int r)
{
if(r<low || high<l)return INT_MAX; // no overlap
if(low>=l && high<=r)return seg[index]; // partial Overlap
int mid = (low+high)/2;
int left = query(2*index+1,low,mid,l,r);
int right = query(2*index+2,mid+1,high,l,r);
return min(left,right);
}
void update(int index,int low,int high,int i,int val)
{
if(low==high)
{
seg[index] = val;
return;
}
int mid = (low+(high-low)/2);
if(i<=mid)update(2*index+1,low,mid,i,val);
else update(2*index+2,mid+1,high,i,val);
seg[index] = min(seg[2*index+1],seg[2*index+2]);
}
};
class SegmentTreeWithLazy{
public:
vector<int>seg,lazy;
SegmentTreeWithLazy(int n)
{
seg.resize(4*n);
lazy.resize(4*n);
}
public:
void build(int index,int low,int high,vector<int>&v)
{
if(low==high)
{
seg[index] = v[low];
return;
}
int mid = (low+(high-low)/2);
build(2*index+1,low,mid,v);
build(2*index+2,mid+1,high,v);
seg[index] = seg[2*index+1]+seg[2*index+2];
}
public:
void update(int index,int low,int high,int l,int r,int val){
if (lazy[index] != 0)
{
seg[index] += (high-low+1)*lazy[index];
if (low != high)
{
lazy[index*2 + 1] += lazy[index];
lazy[index*2 + 2] += lazy[index];
}
lazy[index] = 0;
}
if (low>high || low>r || high<l)
return ;
if (low>=l && high<=r)
{
seg[index] += (high-low+1)*val;
if (high != low)
{
lazy[index*2 + 1] += val;
lazy[index*2 + 2] += val;
}
return;
}
int mid = (high+low)/2;
update(index*2+1,low, mid, l,r,val);
update(index*2+2,mid+1,high,l,r,val);
seg[index] = seg[index*2+1] + seg[index*2+2];
}
public:
int query(int index,int low,int high,int l,int r)
{
// update if the updates are remaining
if(lazy[index]!=0)
{
seg[index]+=(high-low+1)*lazy[index];
if(low!=high)
{
lazy[2*index+1]+=lazy[index];
lazy[2*index+2]+=lazy[index];
}
lazy[index] = 0;
}
if(high<l || r<low)return 0;
if(low>=l && high<=r)return seg[index];
int mid = (low+(high-low)/2);
int left = query(2*index+1,low,mid,l,r);
int right = query(2*index+2,mid+1,high,l,r);
return left+right;
}
};
ll gcd(ll a, ll b)
{
if (!a)
return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b){
ll y = gcd(a,b);
return a / y * b;
}
void BuildSegmentTree(int index,int low,int high,vector<int>&v,bool XORTurn,vector<int>&seg)
{
if(low==high)
{
seg[index] = v[low];
return;
}
int mid = (low+high)/2;
BuildSegmentTree(2*index+1,low,mid,v,!XORTurn,seg);
BuildSegmentTree(2*index+2,mid+1,high,v,!XORTurn,seg);
if(XORTurn)seg[index] = seg[2*index+1]^seg[2*index+2];
else seg[index] = seg[2*index+1]|seg[2*index+2];
return;
}
bool isValid(int row,int col,int n)
{
if(row>=0 && row<n && col>=0 && col<n)return true;
return false;
}
void createSieve(vector<int>&sieve)
{
for(int i=2;i*i<=300000;i++)
{
if(sieve[i]==-1)
{
for(int j=i*i;j<=300000;j+=i)
{
sieve[j] = i;
}
}
}
}
void solve(int g)
{
int n,k;
cin>>n>>k;
string str;
cin>>str;
sort(str.begin(),str.end());
set<char>s;
for(int i=0;i<k;i++)s.insert(str[i]);
if(s.size()==1)
{
s.erase(s.begin(),s.end());
for(int i=k;i<n;i++)s.insert(str[i]);
if(s.size()==1)
{
int left = n-k;
int mini = left/k;
cout<<str[k-1];
for(int i=0;i<mini;i++)cout<<str[k];
if(left%k!=0)
{
cout<<str[k]<<endl;
return;
}
cout<<endl;
}
else
{
cout<<str[k-1];
cout<<str.substr(k)<<endl;
return;
}
}
else
{
cout<<str[k-1]<<endl;
return;
}
}
int main()
{
#ifndef ONLINE_JUDGE
// for getting input from in
freopen("input.txt","r",stdin);
freopen("Error.txt","w",stderr);
// for writing output to output.txt
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
int g = 1;
while(t--)
{
solve(g);
g++;
}
return 0;
}
426A - Sereja and Mugs | 363A - Soroban |
1585C - Minimize Distance | 1506E - Restoring the Permutation |
1539A - Contest Start | 363D - Renting Bikes |
1198D - Rectangle Painting 1 | 1023B - Pair of Toys |
1725A - Accumulation of Dominoes | 1675E - Replace With the Previous Minimize |
839A - Arya and Bran | 16B - Burglar and Matches |
1625B - Elementary Particles | 1725G - Garage |
1725B - Basketball Together | 735A - Ostap and Grasshopper |
1183B - Equalize Prices | 1481A - Space Navigation |
1437B - Reverse Binary Strings | 1362B - Johnny and His Hobbies |
1299A - Anu Has a Function | 1111A - Superhero Transformation |
954A - Diagonal Walking | 39F - Pacifist frogs |
1451C - String Equality | 386A - Second-Price Auction |
1690E - Price Maximization | 282B - Painting Eggs |
440A - Forgotten Episode | 233B - Non-square Equation |